#include <stdio.h>
#include <stdlib.h>
#include <csp_spu.h>
#include <csp_debug.h>
#include "../ct.h"


int global_pid; 


int Run(){

	int pid = csp_pid();
	global_pid = csp_pid();

	int x __attribute__ ((aligned(16)));
	int i;

	csp_channel in = 
		csp_create_channel(ONE2ONE_CHANNEL, D_CHANNEL, sizeof(int));

	// Warm up: read 1000 numbers
	for(i=0; i < 1000; i++ ){
		csp_channel_read(in, &x);
	}
	printf("Finished warming up. Start timing commstime benchmark\n.");

	while( 1 ){
		csp_timing_start();
		for(i = 0; i < N_LOOPS; i++){
			csp_channel_read(in, &x);
		}
		csp_timing_stop();
	}
		
	ASSERT( pid == csp_pid() );
	ASSERT( global_pid == csp_pid() );

	PRINTF_FOR_TESTING("%s terminating on spe #%i with pid %i\n",__FILE__ , csp_spe_id(), pid);

	PRINTF_FOR_TESTING("Nested task with pid=%i terminated with res=%i.\n", pid, res);

	return 0;
}
